import {
  Controller,
  Get,
  Post,
  Body,
  Put,
  Param,
  Delete,
} from '@nestjs/common';
import { PostsService } from './posts.service';
import CreatePostDto from './dto/create-post.dto';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import UpdatePostDto from './dto/update-post.dto';

@Controller('posts')
@ApiTags('Post')
export class PostsController {
  constructor(private readonly postsService: PostsService) {}

  @Get()
  @ApiOperation({ summary: 'find all' })
  findAll() {
    return this.postsService.findAllPost();
  }

  @Post()
  @ApiOperation({ summary: 'post one' })
  createOne(@Body() body: CreatePostDto) {
    return this.postsService.createPost(body);
  }

  @Put(':id')
  @ApiOperation({ summary: 'update one' })
  updateOne(@Body() body: UpdatePostDto, @Param('id') _id: string) {
    return this.postsService.updatePost(body, _id);
  }

  @Delete(':id')
  @ApiOperation({ summary: 'delete one' })
  deleteOne(@Param('id') _id: string) {
    return this.postsService.deletePost(_id);
  }
}
